// StringTableEntryConverter.cs
//
// Copyright (c) 2007 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Globalization;
using System.Windows.Data;

using Supremacy.Text;

namespace Supremacy.Editor
{
    [ValueConversion(typeof(String), typeof(String))]
    public class StringTableKeyToNameConverter : IValueConverter
    {
        private EditorContext EditorContext
        {
            get { return EditorApp.CurrentEditor.EditorContext; }
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                try
                {
                    StringTableEntry entry = EditorContext.StringTable.FindEntry((string)value);
                    if (entry != null)
                        return entry.Value;
                }
                catch { }
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
